/*
 * dynamic_array.cpp
 *
 *  Created on: 10.10.2011
 *      Author: duke
 */

#include <iostream>
#include <vector>
#include "dynamic_array.h"

using namespace std;

dynamic_array::dynamic_array() {
}
;

dynamic_array::dynamic_array(int rows, int cols) {
	this->rows = rows;
	this->cols = cols;
	for (int i = 0; i < this->rows; i++) {
		data_.push_back(std::vector<int>(cols));
	}
}

vector<int> & dynamic_array::operator[](int i) {
	return data_[i];
}

const vector<int> & dynamic_array::operator[](int i) const {
	return data_[i];
}

dynamic_array dynamic_array::operator*(dynamic_array& A) {
	dynamic_array C(getrows(), getcols());
	double ans;
	for (int r = 0; r < getrows(); r++)
		for (int c = 0; c < getcols(); c++) {
			ans = 0;
			for (int i = 0; i < A.getcols(); i++)
				ans = getValue(r, i) * A.getValue(i, c) + ans;
			C[r][c] = ans;
		};

	return (C);
}

int dynamic_array::getrows() {
	return this->rows;
}
int dynamic_array::getcols() {
	return this->cols;
}

int dynamic_array::getValue(int row, int col) {
	return this->data_[row][col];
}

void dynamic_array::resize(int rows, int cols) {
	data_.resize(rows);
	for (int i = 0; i < rows; ++i)
		data_[i].resize(cols);
}

dynamic_array dynamic_array::powerOfTwo() {
	int size = 0;
	if (getcols() == getrows()) {
		size = getcols();
	}
	dynamic_array temp(size, size);
	double ans;
	for (int r = 0; r < size; r++)
		for (int c = 0; c < size; c++) {
			ans = 0;
			for (int i = 0; i < size; i++)
				ans = getValue(r, i) * getValue(i, c) + ans;
			temp[r][c] = ans;
		};

	return (temp);
}

void dynamic_array::print() {
	for (int i = 0; i < this->rows; i++) {
		for (int j = 0; j < this->rows; j++) {
			cout.width(2);
			cout << this->data_[i][j] << " ";
		}
		cout << endl;
	}
}

